package com.aldobucchi.ds.op.mxml
{
	
	
	import mx.collections.ArrayCollection;
	import mx.collections.IList;
	
	import com.aldobucchi.core.dependency.DependencyHelper;
	import com.aldobucchi.core.dependency.DependencySpec;
	import com.aldobucchi.ds.container.IRContainer;
	import com.aldobucchi.ds.op.ContainerToListOp;
	import com.aldobucchi.utils.AbstractMXMLObject;
	import com.aldobucchi.utils.IOperator;

	
	
	
	
	public class ContainerToListCtrl extends AbstractMXMLObject
	{


		private var dh:DependencyHelper;

		
		private var op:IOperator;
		
		
		private var iContainerSpec:DependencySpec = new DependencySpec( "iContainer", "iContainerChanged" );
		[Bindable("iContainer")]
		public function get iContainer( ):IRContainer
		{
			return dh.getDependencyValue( iContainerSpec );
		}

		public function set iContainer( v:IRContainer ):void
		{
			dh.setDependencyValue( iContainerSpec, v );
		}





		private var _oList:IList;
		[Bindable("change")]
		public function get oList( ):IList
		{
			return _oList;
		}



		public function ContainerToListCtrl( )
		{
			
			dh = new DependencyHelper( this, update );
			_oList = new ArrayCollection( );
			
		}
		
		
		
		private function update( ):void
		{
			
			if ( op )
			{
				op.dispose( );
				_oList.removeAll( );
			}
			

			if ( iContainer )
			{
				op = new ContainerToListOp( iContainer, _oList );
			}
			
		}
		
		
	}
}







